load("@com_google_googleapis_imports//:imports.bzl", "cc_proto_library")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

proto_library(
    name = "packetlib_proto",
    srcs = ["packetlib.proto"],
)

cc_proto_library(
    name = "packetlib_cc_proto",
    deps = [
        ":packetlib_proto",
    ],
)

cc_library(
    name = "bit_widths",
    hdrs = ["bit_widths.h"],
)

cc_library(
    name = "packetlib",
    srcs = ["packetlib.cc"],
    hdrs = ["packetlib.h"],
    deps = [
        ":bit_widths",
        ":packetlib_cc_proto",
        "//gutil/gutil:overload",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/string_encodings:bit_string",
        "//p4_pdpi/string_encodings:hex_string",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/numeric:bits",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_library(
    name = "packetlib_matchers",
    testonly = True,
    hdrs = ["packetlib_matchers.h"],
    deps = [
        ":packetlib_cc_proto",
        "//gutil/gutil:proto_matchers",
    ],
)

cc_test(
    name = "packetlib_fuzzer_test",
    srcs = ["packetlib_fuzzer_test.cc"],
    deps = [
        ":packetlib",
        ":packetlib_cc_proto",
        "//gutil/gutil:proto",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi/string_encodings:hex_string",
        "//p4_pdpi/string_encodings:readable_byte_string",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/random:distributions",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "packetlib_unit_test",
    srcs = ["packetlib_unit_test.cc"],
    deps = [
        ":bit_widths",
        ":packetlib",
        ":packetlib_cc_proto",
	"//gutil/gutil:proto_matchers",
	"//gutil/gutil:testing",
        "//gutil/gutil:status_matchers",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_main",
    ],
)

# go/golden-test-with-coverage
cc_test(
    name = "packetlib_test_runner",
    srcs = ["packetlib_test_runner.cc"],
    linkstatic = True,
    deps = [
        ":packetlib",
        ":packetlib_cc_proto",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//gutil/gutil:testing",
        "//p4_pdpi/string_encodings:readable_byte_string",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "packetlib_matchers_test",
    srcs = ["packetlib_matchers_test.cc"],
    deps = [
        ":packetlib_cc_proto",
        ":packetlib_matchers",
        "//gutil/gutil:testing",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "packetlib_debugging_test",
    srcs = ["packetlib_debugging_test.cc"],
    deps = [
        ":packetlib",
        ":packetlib_cc_proto",
	"//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi/string_encodings:readable_byte_string",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_googletest//:gtest_main",
    ],
)

cmd_diff_test(
    name = "packetlib_test",
    actual_cmd = "$(execpath :packetlib_test_runner)",
    expected = "//p4_pdpi/packetlib:packetlib_test_runner.expected",
    tools = [
        ":packetlib_test_runner",
    ],
)
